package com.terrence.filemgr.mgr;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;


public class FilePathGenerator {
	
	private FilePathGenerator(){};
	
	/**
	 * 为系统提供统一的文件管理路径    例 pc/2014/11/
	 */
	public static String generateDirPath(String pathSeperator,String baseDir){
		StringBuffer filePath = new StringBuffer();
		Date date = new Date();
		filePath.append(baseDir);
		filePath.append(pathSeperator);
		filePath.append(dateToStr(date,"yyyy"));
		filePath.append(pathSeperator);
		filePath.append(dateToStr(date,"MM"));
		filePath.append(pathSeperator);
		System.out.println(filePath);
		return filePath.toString();
	}
	
	/**
	 * 
	 * 构建文件名
	 * @param fileType
	 * @return
	 */
	public static String generateFileName(String fileType){
		return UUID.randomUUID().toString()+"."+fileType;
	}
	
	private static String dateToStr(Date date, String format) {
		if(null == date || StringUtils.isEmpty(format)){
			return "";
		}
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		return formatter.format(date);
	}
}
